<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html,
        body {
            background-color: pink;
        }

        .box {
            width: 452px;
            height: 452px;
            margin: 50px auto;
            border: 1px solid #fff;
            font-size: 0;
            border-collapse: collapse;
            overflow: hidden;
            background-color: rgb(103, 145, 236);
        }

        .box ul {
            line-height: 150px;
            text-align: center;
        }

        .box ul li {
            display: block;
            width: 150px;
            height: 150px;
            font-size: 20px;
            list-style: none;
            border: 1px solid #fff;
            float: left;
            color: rgb(179, 28, 111);
            border-collapse: collapse;
        }

        .box ul a {
            display: block;
            width: 150px;
            height: 150px;
            font-size: 40px;
            text-decoration: none;
            border: 1px solid #fff;
            float: left;
            background-color: rgb(79, 182, 196);
        }

        p {
            color: rgb(79, 182, 196);
            font-size: 50px;
        }

        .you {
            background-color: rgb(79, 182, 196);

        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="pink you">赵丽颖</li>
            <li class="pink">胡歌</li>
            <li class="pink">迪丽热巴</li>
            <li class="pink">彭于晏</li>
            <a href="#" class="Start">开始</a>
            <li class="pink">苏恋雅</li>
            <li class="pink">张艺兴</li>
            <li class="pink">张子枫</li>
            <li class="pink">彭昱畅</li>
        </ul>
    </div>
    <script>
        var pinks = document.querySelectorAll('.pink');
        var Start = document.querySelector('.Start');

        var arr = [0, 1, 2, 4, 7, 6, 5, 3]

        Start.onclick = function () {

            // console.log('159');
            var i = 0;
            var j = 1;
            var num = 0
            var time = setInterval(function () {
                // console.log('357');
                if (pinks[arr[i]].classList.contains('you')) {
                    pinks[arr[i]].classList.remove('you');
                    pinks[arr[j]].classList.add('you');
                    console.log(arr[i]);
                    console.log(arr[j]);
                }
                if (j === pinks.length - 1) {
                    j = 0;
                }
                else {
                    j++;
                }
                if (i === pinks.length - 1) {
                    i = 0;
                }
                else {
                    i++
                }
                num++;

                if (num >= Math.floor(Math.random() * 21 + 24)) {
                    clearInterval(time);
                }
                console.log(num);
            }, 50)

        }






    </script>
</body>

</html>